<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
%>

<!DOCTYPE html>
<html lang="zh-cn" xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="keywords" content="" />
	<meta name="description" content="" />
	<title>云医通开放性接口平台</title>
	<link rel="stylesheet" type="text/css" href="./css/mserver.css" />
	<link rel="stylesheet" type="text/css" href="./css/calender.css" />
	<link rel="stylesheet" type="text/css" href="./css/mserverother.css" />
	<link rel="stylesheet" type="text/css" href="./css/tip-yellow.css" />
	<link rel="stylesheet" type="text/css" href="./css/tip-darkgray.css" />
	<link rel="stylesheet" type="text/css" href="./css/tableStyle.css" />
	<script src="./js/jquery-1.8.0.min.js"></script>
	<script src="./js/Common.js"></script>
	<script src="./js/jquery.poshytip.min.js"></script>
</head>

<body>
<div class="mserver imenu">
	<div class="header">
		<div class="inner cf" style="position: relative;">
			<a title="云医通开放性接口平台系统" target="_blank" href="#">
				<h2><span></span></h2>
			</a>
			<ul>
				<li>
					<a id="documentCenter" title="文档中心" target="_self">文档中心</a>
					<em style="display: block; margin-top: -1px; height: 8px;"></em>
				</li>

				<li>
					<a id="applicationCenter" href="javascript:void(0);" title="" target="_self">应用接入</a>
				</li>
			</ul>
			<div class="ibtn">
				<a href="javascript:void(0);" title="登录" target="_self" class="btn_log"><span>登录</span></a>
				<a style="cursor: pointer;" title="设置个人信息" target="_self" class="btn_info" href="javascript:void(0);"><span>设置个人信息</span></a>
			</div>
			<div style="clear: right;"></div>
                <div class="ibtn" style="position: absolute; bottom: 0px; right: 0px;">
                    <input id="txt_Search" type="text" />
                    <a href="javascript:Public.SearchAPI();" title="查找" target="_self" class="btn_Search"><span>查找</span></a>
                </div>
		</div>
	</div>
	<input type="hidden" id="local_url" value="" />

	<div class="open_wrap">
		<table>
			<tr>
				<td>接口地址：</td>
				<td colspan="3">
					<%--<input id="txt_url" type="text" style="width: 500px;" value="https://14.18.207.75:7474/openapi/rest" /></td>--%>
					<input id="txt_url" type="text" style="width: 500px;" value="dubbo://127.0.0.1:20881" /></td>
			</tr>
			<tr>
				<td>Appid：</td>
				<td><input id="txt_appid" type="text" style="width: 250px;" /></td>
				<td>Securitykey：</td>
				<td><input id="txt_securitykey" type="text" style="width: 250px;" /></td>
				<td><input id="btn_GetSession" type="button" value="获取调用权限" style="width: 90px;" /></td>
			</tr>
			<tr>
				<td>session：</td>
				<td><input id="txt_session" type="text"  readonly="readonly" style="width: 250px;" /></td>
				<td>appkey：</td>
				<td><input id="txt_appkey" type="text" readonly="readonly" style="width: 250px;" /></td>
			</tr>
			<tr>
				<td>接口方法：</td>
				<td><input id="txt_method" type="text" style="width: 250px;" /></td>
			</tr>
			<tr>
				<td>提交的数据：</td>
				<td colspan="3"><textarea id="txt_data" cols="20" rows="5" style="width: 100%;"></textarea></td>
				<td valign="top"><input id="btn_Submit" type="button" value="提交" style="width: 90px;" /></td>
			</tr>
			<tr>
				<td>返回的结果：</td>
				<td colspan="3"><textarea id="txt_result" cols="20" rows="5" style="width: 100%;"></textarea></td>
			</tr>
		</table>
	</div>
	<!-- end of open_wrap -->

	<div class="footer" style="clear: both; margin-top: 600px;">
		<p>Copyright &copy; 广州云医科技有限公司 2015-2016, All Rights Reserved</p>
	</div>

	<a href="#" class="go_top"></a>
</div>

<script type="text/javascript">
	var apiid = '';

	// 获取接口信息
	function Api_Callback(ret) {
		if (ret ) {
			if ($.trim(ret[0].apiClassId).length == 0) {
				alert('参数错误');
//				window.location.href = "Document.jsp";
				return;
			}

			$('#txt_method').val(ret[0].apiDefine);

		}
	}

	function Apistruct_Callback(ret){
		Public.ajaxPost(window.parent.path + apis["getParamstruct"] + '?structId=' + ret[0].structId, null, Paramstruct_Callback, null);
	}

	function Paramstruct_Callback(ret){
		$('#txt_data').val(ret[0].example);
	}

	//GetSession回调函数
	function GetSession_Callback(ret) {
		if (ret) {
			var session=ret["session"];
			var appkey=ret["appkey"];
			set_value('txt_session',session);
			set_value('txt_appkey',appkey);
		}
	}

	function json2str(o) {
		            var arr = [];
		          var fmt = function(s) {
			               if (typeof s == 'object' && s != null) return json2str(s);
			                return /^(string|number)$/.test(typeof s) ? "'" + s + "'" : s;
				  }
		            for (var i in o) arr.push("'" + i + "':" + fmt(o[i]));
		            return '{' + arr.join(',') + '}';
	}
	
	function set_value(object_id, new_value) {
		document.getElementById(object_id).value = new_value;
	}

	//Submit回调函数
	function Submit_Callback(ret) {
		$('#txt_result').val(json2str(ret));
	}

	function CheckUrl() {
		apiId = Public.GetUrlParam('apiId');

		if ($.trim(apiId).length == 0) {
			alert('参数错误');
//			window.location.href = "Document.jsp";
		}
	}

	$(function () {
		CheckUrl();
		path = "<%=path%>/";
		Public.ajaxPost(window.parent.path + apis["getApi"] + '?apiId=' + apiId, null, Api_Callback, null);
		Public.ajaxPost(window.parent.path + apis["getApistruct"] + '?apiId=' + apiId+"&apiStructType=1", null, Apistruct_Callback, null);


		$("#btn_GetSession").bind('click', function () {

			var appid=$('#txt_appid').val();
			var url=$('#txt_url').val();
			var securitykey=$('#txt_securitykey').val();

			Public.ajaxPost(window.parent.path + '/getToken.do?url=' + url+'&username='+appid+'&password='+securitykey, null, GetSession_Callback, null);
		});

		$("#btn_Submit").bind('click', function () {

			var appid=$('#txt_appid').val();
			var url=$('#txt_url').val();
			var method=$('#txt_method').val();
			var session=$('#txt_session').val();
			var appkey=$('#txt_appkey').val();
			var data=$('#txt_data').val();

			Public.ajaxPost(window.parent.path + 'methodInvoke.do?url=' + url+'&username='+apiId+'&session='+session+'&method='+method+'&appkey='+appkey+'&data='+data, null, Submit_Callback, null);
		});

		$(".show").click(function () {
			Public.Fold(this);
		});
	});
</script>

</body>
</html>
